package com.ziyun.erp.modules.goods.service.impl;

import com.sun.javafx.collections.MappingChange;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;

import com.ziyun.erp.modules.goods.dao.GoodsHotsellDao;
import com.ziyun.erp.modules.goods.entity.GoodsHotsellEntity;
import com.ziyun.erp.modules.goods.service.GoodsHotsellService;
import com.ziyun.erp.modules.goods.VO.GoodsHotsellVo;


@Service("goodsHotsellService")
public class GoodsHotsellServiceImpl extends ServiceImpl<GoodsHotsellDao, GoodsHotsellEntity> implements GoodsHotsellService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Page<GoodsHotsellVo> page = new Page<>(Integer.parseInt(params.get("page").toString()),
                Integer.parseInt(params.get("limit").toString()));
        page.setRecords(this.baseMapper.selectSourceList(page, params));
        return new PageUtils(page);
    }

    @Override
    public R saveInfo(GoodsHotsellEntity goodsHotsell) {
        Long goodsId = goodsHotsell.getGoodsId();
        int count = this.selectCount(new EntityWrapper<>(new GoodsHotsellEntity()).eq("goods_id", goodsId));
        if (count > 0) {
            return R.error("商品已存在");
        }
        baseMapper.insert(goodsHotsell);
        return R.ok();

    }

    /**
     * 伪删除
     * @param id
     */
 /*   public void deleteUpdate(Integer id) {
        Map<String, Object> map = new HashMap<>();
        map.put("", 1);
        this.baseMapper.updateByMap(map, id);
    }*/

}
